//index.js
//获取应用实例
const util = require('../../utils/util.js');
const app = getApp();
Page({
  data: {
    showMore: false,
    page: 1, //页码
    datas: [], //页面数据
    hot: 2,
    allPage: 0 //总页码
  },
  onLoad: function() { 
    getList(this);
    this.getRecommend()
  },
  //下拉刷新页面
  onPullDownRefresh() {
    this.setData({
      page: 1,
    });
    getList(this);
  },
  //上拉加载更多
  onReachBottom() {
    if (this.data.page < this.data.allPage) {
      this.setData({
        page: this.data.page + 1
      })
      getList(this);
    } else {
      wx.showToast({
        title: '没有更多数据',
        image: '../img/notdata.png',
      });
    }
  },
  onShareAppMessage() {

    let that = this;
    setTimeout(function() {
      that.setData({
        showMore: true,
      })
    }, 1000);
    let _data = this.data.datas[0];
    return {
      title: _data.title,
      path: 'pages/index/index?id=' + _data.id + '&share=1',
      imageUrl: _data.thumb
    }
  },
  //刷新方法并提示
  replace() {
    wx.pageScrollTo({
      scrollTop: 0
    });
    this.setData({
      page: 1,
    });
    getList(this);
  },
  //跳转详情 
  goToPage(e) {  
    
    if (e.currentTarget.dataset.islink == 1) {
      wx.navigateTo({
        url: '/pages/info/info?id=' + e.target.id
      });
    } else {
      wx.navigateTo({
        url: '/pages/webview/webview?url=' + e.currentTarget.dataset.thumb
      });
    }
  },
  //收集formID
  formInSign(e) {

    let userInfo = wx.getStorageSync('user');
    let formId = e.detail.formId;
    if (formId == 'the formId is a mock one') {

      return false;
    }
    if (formId && userInfo) {

      postFormId(userInfo.openid, formId);
    }
  },
  //获取推荐
  getRecommend() { 
    getInfoRec(this)
  },
  //关闭更多
  closeMore() {
    this.setData({
      showMore: false,
    })
  },
  //查看更多
  watchMore() {

    wx.reLaunch({
      url: '../index/index'
    })

  },

})